<template>
  <div class="my-post">
    <x-header>我的关注</x-header>
      <div class="total-num"><span>全部关注</span> <span style="color:#abbac1;">{{watchList.length}}</span> <span>人</span></div>
      <div class="commentList">
        <div class="attention-item" @click.native="$router.push(`/personindex?userId=${item.user2Id}`)" v-for="(item,i) in watchList" :key="i">
          <div class="top">
            <div class="left">
              <avatar :src="item.user2Obj && item.user2Obj.avatar" username="Lairenna Doe" :size="40"></avatar>
            </div>
            <div class="right">
              <div class="right-1">
                <div>{{item.user2Obj && item.user2Obj.nickname}}</div>
                <div>
                  <span>{{getTime(item.createTime)}}</span>
                </div>
              </div>
              <div class="right-2">
                <i class="icon-plus-transfer" v-if="item.isMutual"></i>
                <i class="icon-yiguanzhu" v-else @click.stop="handleFocusman(item)"></i>
              </div>
            </div>
          </div>
        </div>
      </div>
    <actionsheet
      v-model="showConfirm"
      :menus="cacelList"
      show-cancel
      @on-click-menu="clickMenu">
    </actionsheet>
  </div>
</template>
<script>
import { Vue, Component } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
import Avatar from 'vue-avatar';
import { formatMsgTime } from '../../js/getTime'
// import { getUnixTime } from '../../js/utils'
import {
  Actionsheet,
  XHeader,
  Group
} from 'vux';
const IndexStore = namespace('mine');
const HomeStore = namespace('home');

@Component({
  components: {
    Actionsheet,
    XHeader,
    Group,
    Avatar
  }
})
export default class MyAttention extends Vue {
  @IndexStore.Action getMyWatch;
  @HomeStore.Action getSaveCollect;
  @IndexStore.State watchList;
  @HomeStore.Action getWatchUser;
  @HomeStore.Action getUnWatchPost;
  @HomeStore.State watchUser;
  currentItem = null
  showConfirm = false
  cacelList = {
  	1: '取消关注',
    2: '举报'
    // 3: '不看此人'
  }
  clickMenu (key, value) {
    if (key === '2') {
      const { user2Obj } = this.currentItem;
      const info = {
        _id: user2Obj._id,
        targetId: user2Obj._id,
        creator: user2Obj,
        type: 'user'
      }
      this.$router.push({
        path: `/report`,
        query: {
          info
        }
      })
    }
    if (key === '1') {
      this.handleFocusman(this.currentItem)
    }
  }
  getTime (t) {
    return formatMsgTime(t * 1000)
  }
  created () {
    this.getMyWatch()
  }
  handleRemove (item) {
    this.currentItem = item
    this.id = item._id
    this.showConfirm = true
  }
  handleFocusman (val) {
    const params = {
      status: 1,
      user2Obj: val.user2Obj
    }
    this.getWatchUser(params).then(msg => {
      if (msg) {
        this.$vux.toast.text(msg, 'middle');
      } else {
        this.$vux.toast.text('已取消关注', 'middle');
        this.getMyWatch()
      }
    })
  }
}
</script>
<style lang="less">
.my-post {
  padding-top: 51px;
  .total-num {
    line-height: 40px;
    background: #ffffff;
    border-radius: 10px;
    width: 95%;
    margin: 0 auto;
    margin-bottom: 5px;
    padding-left: 10px;
    box-sizing: border-box;
    span {
      color: #414141;
    }
  }
  .attention-item {
    width: 95%;
    margin: 0 auto;
    border-radius: 10px;
    background: #ffffff;
    margin-bottom: 5px;
    padding: 10px 20px;
    box-sizing: border-box;
  }
  .commentList {
      // font-size: 12px;
      .main {
        // font-size: 12px;
      }
      .weui-cells {
        margin-top: 0;
      }
      .weui-cell__ft {
        text-align: left;
        width: 100%;
      }
      .top {
        width: 100%;
        height: 70px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .left {
          width: 20%;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
        }
        .right {
          // font-size: 12px;
          width: 80%;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: space-between;
        }
        .right-1 {
          display: flex;
          flex-direction: column;
        }
        .right-2 {
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }
}
</style>
